//
//  ViewController.m
//  WeixinLoginDemo
//
//  Created by lanou3g on 16/4/8.
//  Copyright © 2016年 张静. All rights reserved.
//

#import "ViewController.h"
#import "WXApi.h"
#import "AppDelegate.h"
@interface ViewController ()<WXLoginDelegate>
//头像
@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
//用户名
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
#pragma mark------微信登录方法
- (IBAction)loginAction:(id)sender {
//    判断微信客户端
    if ([WXApi isWXAppInstalled]) {
        [self sendAuthRequest];
    }
}
//请求微信登录
- (void)sendAuthRequest {
    SendAuthReq *request = [[SendAuthReq alloc]init];
//    请求微信登录授权权限
    request.scope = @"snsapi_userinfo";
//应用申请微信登录标识
    request.state = @"蓝鸥3G";
//    发送
    [WXApi sendReq:request];
}
//展示用户数据
- (void)wxLoginReceiveDict:(NSDictionary *)userInfo{
    NSString *imageUrlStr = userInfo[@"headerImageUrl"];
    NSString *userName = userInfo[@"nickName"];
//    获取图片Data
    NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrlStr]];
    UIImage *image = [UIImage imageWithData:imgData];
//    展示
    dispatch_async(dispatch_get_main_queue(), ^{
        self.headerImageView.image = image;
        self.userNameLabel.text = userName;
    });
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
